var e = require("../../../utils/function.js"), t = require("../../../api.js"), a = require("../../../utils/qqmap-wx.js"), o = getApp(), n = wx.getStorageSync("MAP_KEY") || "PNIBZ-QF5R2-XSGUL-CGVXI-5J4GZ-VNFNX", i = new a({
  key: n
});

Page({
  data: {
      travel_type:1,
      estimated_form_time:'',
      newtop:false,
      showNum: 1,
      online: !1,
      authorize: "",
      showMask: !1,
      showClass: !1,
      jumpList: [],
      timer: null,
      flag: 1,
      showDriver: "0",
      driverPosition: {
          lat: 0,
          lng: 0
      },
      showTips: !1,
      fenxiaoId: "",
      authStatus: !0,
      is_GZH: !1,
      canIUse: wx.canIUse("button.open-type.getUserInfo"),
      img: e.userImg,
      markers: {},
      polyline: [ {
          points: [],
          color: "#0299de",
          width: 9,
          dottedLine: !1,
          arrowLine: !0
      } ],
      controls: [ {
          id: 1,
          iconPath: "../../../images/user/icon-22.png",
          position: {
              left: 10,
              top: 10,
              width: 50,
              height: 50
          },
          clickable: !0
      } ],
      drivers: [ {
          id: "001",
          title: "1名司机"
      }, {
          id: "002",
          title: "2名司机"
      }, {
          id: "003",
          title: "3名司机"
      }, {
          id: "004",
          title: "4名司机"
      }, {
          id: "005",
          title: "5名司机"
      }, {
          id: "006",
          title: "6名司机"
      }, {
          id: "007",
          title: "7名司机"
      }, {
          id: "008",
          title: "8名司机"
      } ],
      startAddress: null,
      istail:'出租车',
      endAddress: null,
      longitude: null,
      latitude: null,
      orderOrMore: !0,
      driverCount: -1,
      pageRight: 0,
      myShow: !0,
      zuoyou: "icon-zuoyou",
      avatar: "../../../images/user/icon-07.png",
      buttonText: "登录",
      username: "未登录",
      orderGoing: !1,
      showTimeContainer: !1,
      date: [ "今天", "明天", "后天" ],
      hours: [],
      minute: [],
      homeHandlerShow: !0,
      about_time: [],
      phone: "",
      make: {},
      Hmap: "",
      left_width: 650,
      is_distance: !1,
      price: "0.00",
      show_alert_info: !1,
      userAddress: {
          location: {
              lat: "null",
              lng: "null"
          }
      },
      isReadProtocol: !0,
      get_order: wx.getStorageSync("get_order"),
      show_bind_phone: !1,
      scale: 15,
      isAddressText: !0,
     
  },
  onReady: function() {
      // var p = require("../../../utils/function.js") 
      // console.log(p.getLatLntHandler())
      console.log(getApp().nowcity);
      
      var e = this;

      this.animation = wx.createAnimation(), this.onlineCallbackVar = function(t) {
          e.setData({
              online: t
          });
      }, o.wsAddOnline(this.onlineCallbackVar);
  },
  onLoad: function(t) {
    console.log(t);
    
    wx.getLocation({
        type: "gcj02",
        success: (t) => {
            var that = this
            var n = t.latitude,
                a = t.longitude,
                o = (t.speed, t.accuracy, t.latitude + "," + t.longitude);
            
            wx.request({
                url: "https://apis.map.qq.com/ws/geocoder/v1/?l&get_poi=1",
                data: {
                    key: "YLFBZ-WHAWI-ZXUGH-53Q65-TOJ7E-ADBNQ",
                    location: o
                },
                method: "GET",
                success: (t) => {
                  
                    that.setData({
                        nowcity: t.data.result.ad_info.city,
                    })
                  
                     
                },
                fail: function () {
                    e.getlocation();
                },
                complete: function (e) {}
            });
        }
    });




   
    // wx.getStorage({
    //   key: 'nowcity',
    //   success: function (res) {
    //       console.log(res);
    //       let usercity  = res.data
    //       that.setData({nowcity:usercity})
    //   }
    // })









      var a = this;
      this.getJumpAppList();
      var n = this;
      wx.getLocation({
          type: "gcj02",
          success: function(e) {
              n.data.driverPosition.lat = e.latitude, n.data.driverPosition.lng = e.longitude, 
              n.get_driver_lat_lng();
          },
          fail: function(e) {
              2 == e.errCode && wx.showToast({
                  title: "请打开手机GPS定位服务",
                  icon: "none"
              });
          }
      }), wx.getStorageSync("user_info") || this.setData({
          showTips: !0
      }), this.getAuthorizationImg(), o.getMapSetting(this), t !== {} && t.uid && o.shareCouponsMessage(t.uid), 
      t.scene && ("driverId" == t.scene.split("_")[0] ? this.excId = t.scene.split("_")[1] : (this.fenxiaoId = t.scene, 
      wx.setStorageSync("scene", t.scene))), "true" == t.deleteOrder && wx.showModal({
          title: "提示",
          content: "代驾人员已取消订单",
          showCancel: !1,
          success: function(e) {}
      }), e.getLatLntHandler(function(e) {
          a.setData({
              startAddress: e,
              userAddress: e
          });
      }), this.getLatlngPower(), this.changeIcon();
  },
  callPolice: function() {
      wx.makePhoneCall({
          phoneNumber: "110"
      });
  },
  toappointment: function(e) {
    console.log(e.currentTarget.dataset.url);
    var p = e.currentTarget.dataset.type
  var n =  e.currentTarget.dataset.url
    wx.navigateTo({
      url: n + '?type='+ p,
    })
},
  checkCoupon: function() {
      var e = this;
      o.request({
          url: t.user.checkCoupon,
          method: "post",
          data: {},
          success: function(t) {
              1 == t.code && 1 == t.data.hasNew && (o.cache("couponMask", !0, 86400), e.setData({
                  showMask: !0
              }));
          }
      });
  },
  hideCoupon: function() {
      this.setData({
          showMask: !1
      });
  },
  toDetail: function(e) {
      var t = e.currentTarget.dataset.url;
      console.log(e);
     var p = e.currentTarget.dataset.istail;
      e.currentTarget.dataset.way && this.setData({
          showMask: !1
      }), wx.navigateTo({
          url: t + '?istail=' + p
      });
  },
  changeLength: function(e) {
      var t = e.currentTarget.dataset.idx;
      this.animation.translate(this.data.showClass ? 0 : -59).step();
      var a = {};
      a[t] = this.animation.export(), this.setData({
          showClass: !this.data.showClass,
          animation: a
      });
  },
  jumpApp: function(e) {
      var t = e.currentTarget.dataset.path, a = e.currentTarget.dataset.appid;
      wx.navigateToMiniProgram({
          appId: a,
          path: t,
          fail: function(e) {}
      });
  },
  getJumpAppList: function() {
      var e = this;
      o.request({
          url: t.default.jump_app_list,
          method: "post",
          success: function(t) {
              1 == t.code && e.setData({
                  jumpList: t.data
              });
          }
      });
  },
  closeTips: function() {
      this.setData({
          showTips: !1
      });
  },
  order_check: function() {
      wx.getStorageSync("access_token") && o.request({
          url: t.order.order_check,
          method: "post",
          data: {},
          success: function(e) {
              if (1 != e.code) return wx.showToast({
                  title: e.msg,
                  icon: "none"
              }), !1;
              1 == e.data.type && wx.showModal({
                  title: "提示",
                  content: "您有订单未支付，请前往支付",
                  success: function(t) {
                      t.confirm ? wx.navigateTo({
                          url: "/pages/pay/paidOrder/paidOrder?order_no=" + e.data.order_no
                      }) : t.cancel;
                  }
              });
          }
      });
  },
  getLatlngPower: function() {
      var e = this;
      wx.getSetting({
          success: function(t) {
              void 0 != t.authSetting["scope.userLocation"] && 1 != t.authSetting["scope.userLocation"] ? wx.showModal({
                  title: "请求授权当前位置",
                  content: "需要获取您的地理位置，请确认授权",
                  success: function(t) {
                      t.cancel ? wx.showToast({
                          title: "拒绝授权",
                          icon: "none",
                          duration: 1e3
                      }) : t.confirm && wx.openSetting({
                          success: function(t) {
                              1 == t.authSetting["scope.userLocation"] ? (e.order_check(), wx.showToast({
                                  title: "授权成功",
                                  icon: "success",
                                  duration: 1e3
                              })) : wx.showToast({
                                  title: "授权失败",
                                  icon: "none",
                                  duration: 1e3
                              });
                          }
                      });
                  }
              }) : (t.authSetting["scope.userLocation"], e.get_line_and_count_distance(), e.get_driver_lat_lng());
          }
      });
  },
  regionchange: function(e) {
      if (this.setData({
          isAddressText: !1
      }), "end" == e.type && ("scale" == e.causedBy || "drag" == e.causedBy)) {
          var t = this;
          this.mapCtx = wx.createMapContext("map"), this.mapCtx.getCenterLocation({
              type: "gcj02",
              success: function(e) {
                  e.latitude, e.longitude;
                  t.setData({
                      userAddress: {
                          location: {
                              lat: e.latitude,
                              lng: e.longitude
                          }
                      }
                  }), t.addressName(e.latitude + "," + e.longitude);
              }
          });
      }
  },
  addressName: function(e) {
      var t = this;
      wx.request({
          url: "https://apis.map.qq.com/ws/geocoder/v1/?l&get_poi=1",
          data: {
              key: n,
              location: e
          },
          method: "GET",
          success: function(e) {
              
              var a = t.data.startAddress, o = e.data.result;
              o.pois[0] && (a = {
                  title: o.pois[0].title,
                  address: o.pois[0].address,
                  location: {
                      lat: o.pois[0].location.lat,
                      lng: o.pois[0].location.lng
                  }
              }), t.setData({
                  startAddress: a,
                  isAddressText: !0
              });
          },
          fail: function() {},
          complete: function() {}
      });
  },
  isRead: function(e) {
      var t = this.data.isReadProtocol;
      this.setData({
          isReadProtocol: !t
      });
  },
  gotoNews: function() {
      wx.navigateTo({
          url: "/pages/user/news/news"
      });
  },
  gotoMine: function() {
      this.clearAddressAndInfo(), wx.switchTab({
          url: "/pages/map/my/my"
      });
  },
  resetCenter: function() {
      var t = this;
      e.getLatLntHandler(function(e) {
          t.setData({
              userAddress: e,
              startAddress: e
          });
      });
  },
  clearAddressAndInfo: function() {
      var t = this;
      t.setData({
          startAddress: null,
          endAddress: null,
          make: {},
          polyline: [ {
              points: [],
              color: "#0299de",
              width: 9,
              dottedLine: !1,
              arrowLine: !0
          } ],
          is_distance: !1,
          price: "0.00",
          show_alert_info: !1,
          about_time: [],
          driverCount: -1
      }), e.getLatLntHandler(function(e) {
          t.setData({
              startAddress: e,
              userAddress: e
          });
      }), t.get_line_and_count_distance();
  },
  controltap: function(t) {
      var a = this, o = this;
      1 === t.controlId ? (o.clearAddressAndInfo(), wx.navigateTo({
          url: "/pages/map/my/my"
      })) : e.getLatLntHandler(function(e) {
          a.setData({
              userAddress: e,
              startAddress: e
          });
      });
  },
  openMyPageHandler: function() {
      var e = this.data, t = (e.pageRight, e.myShow);
      t ? this.setData({
          pageRight: 620,
          left_width: 130,
          myShow: !t,
          controls: [ {
              id: 1,
              iconPath: "../../../images/user/icon-33.png",
              position: {
                  top: 144,
                  left: 10,
                  width: 41,
                  height: 41
              },
              clickable: !0
          } ],
          homeHandlerShow: !1
      }) : (this.setData({
          pageRight: 0,
          left_width: 750,
          myShow: !t,
          controls: [ {
              id: 1,
              iconPath: "../../../images/user/icon-22.png",
              position: {
                  left: 10,
                  top: 10,
                  width: 50,
                  height: 50
              },
              clickable: !0
          }, {
              id: 2,
              iconPath: "../../../images/user/icon-30.png",
              position: {
                  top: 240,
                  left: 10,
                  width: 50,
                  height: 50
              },
              clickable: !0
          } ],
          homeHandlerShow: !0
      }), this.changeIcon());
  },
  callPhoneHandler: function() {
      e.intoPageHandler("../../order/helpFriendDownloadOrder/helpFriendDownloadOrder");
  },
  getMoreDriverHandler: function() {
      this.setData({
          orderOrMore: !this.data.orderOrMore
      });
  },
  bindChange: function(e) {
      this.setData({
          driverCount: e.detail.value[0] + 1
      });
  },
  getDriverCountHandler: function() {
      this.setData({
          orderOrMore: !this.data.orderOrMore
      });
  },
  create_order: function() {
      var a = this;
      wx.showLoading({});
      var n = "" === wx.getStorageSync("relative_people") ? wx.getStorageSync("user") : wx.getStorageSync("relative_people");
      
      o.request({
          
          url: t.order.place_order,
          method: "post",
          data: {
              startAddress: JSON.stringify(this.data.startAddress),
              endAddress: JSON.stringify(this.data.endAddress),
              driver_count: -1 === this.data.driverCount ? 1 : this.data.driverCount,
              passenger_phone: n.phone,
              passenger_name: n.name,
              paid: n.replace_pay ? 1 : 0,
              type: n.type,
              about_time: this.data.about_time,
              hours: this.data.hours,
              minute: this.data.minute,
              dat: this.data.date,
              travel_type : 1
          },
          success: function(n) {
              console.log(n);
              wx.hideLoading(), 1 == n.code ? (wx.getStorageSync("relative_people") && wx.removeStorageSync("relative_people"), 
              wx.canIUse("requestSubscribeMessage") && o.request({
                  url: t.message.getTmplIds,
                  method: "GET",
                  data: {
                      type: 1
                  },
                  success: function(e) {
                      wx.requestSubscribeMessage({
                          tmplIds: e.data,
                          complete: function(e) {}
                      });
                  }
              }), n.data.orderid ? (wx.setStorageSync("orderid", n.data.orderid), a.clearAddressAndInfo(), 
              o.driver(n.data.orderid), wx.navigateTo({
                  url: "../orderAndDriverGoing/orderAndDriverGoing?order_no=" + n.data.orderid
              })) : e.showToast(n.msg, "none")) : (a.open_alert_info(n.msg), 1001 == n.code && setTimeout(function() {
                  a.goToOrder(n.data);
              }, 800));
          }
      });
  },
  create_QR_order: function(a) {
      var n = this;
      wx.showLoading({});
      var i = "" === wx.getStorageSync("relative_people") ? wx.getStorageSync("user") : wx.getStorageSync("relative_people");
      o.request({
          url: t.order.code_order,
          method: "post",
          data: {
              startAddress: JSON.stringify(this.data.startAddress),
              endAddress: JSON.stringify(this.data.endAddress),
              driver_count: -1 === this.data.driverCount ? 1 : this.data.driverCount,
              passenger_phone: i.phone,
              passenger_name: i.name,
              paid: i.replace_pay,
              type: i.type,
              about_time: this.data.about_time,
              hours: this.data.hours,
              minute: this.data.minute,
              dat: this.data.date,
              driverId: a
          },
          success: function(a) {
              wx.hideLoading(), 1 == a.code ? (n.hideQrcode = !0, wx.canIUse("requestSubscribeMessage") && o.request({
                  url: t.message.getTmplIds,
                  method: "GET",
                  data: {
                      type: 1
                  },
                  success: function(e) {
                      wx.requestSubscribeMessage({
                          tmplIds: e.data,
                          complete: function(e) {}
                      });
                  }
              }), a.data.order_no ? (wx.setStorageSync("orderid", a.data.order_no), n.clearAddressAndInfo(), 
              wx.navigateTo({
                  url: "/pages/map/getOrderNotGoing/getOrderNotGoing?showdistance=1&order_no=" + a.data.order_no
              })) : e.showToast(a.msg, "none")) : n.open_alert_info(a.msg);
          }
      });
  },
  open_alert_info: function(e) {
      var t = this;
      this.setData({
          show_alert_info: !0,
          alert_info: e
      }), setTimeout(function() {
          t.setData({
              show_alert_info: !1
          });
      }, 2e3);
  },
  goToOrder: function(e) {
      if (1 == e.is_send && 1 == e.initiate && 1 == e.is_pay) wx.navigateTo({
          url: "/pages/userOrder/orderDetail/orderDetail?order_no=" + e.order_no
      }); else if (0 == e.is_send && 0 == e.apply_delete) wx.navigateTo({
          url: "/pages/map/orderAndDriverGoing/orderAndDriverGoing?order_no=" + e.order_no
      }); else if (1 == e.apply_delete) wx.navigateTo({
          url: "../orderDetail/orderDetail?order_no=" + e.order_no
      }); else if (0 == e.is_service || 4 == e.is_service && 0 == e.apply_delete) wx.navigateTo({
          url: 4 == e.is_service ? "../../map/getOrderNotGoing/getOrderNotGoing?showdistance=1&order_no=" + e.order_no : "../../map/getOrderNotGoing/getOrderNotGoing?order_no=" + e.order_no
      }); else if (0 == e.apply_delete && 1 == e.is_service) wx.navigateTo({
          url: "../../map/orderGoing/orderGoing?order_no=" + e.order_no
      }); else if (0 == e.apply_delete && 2 == e.is_service) {
          if (1 == e.is_pay) return wx.navigateTo({
              url: "/pages/userOrder/orderDetail/orderDetail?order_no=" + e.order_no
          }), !1;
          wx.navigateTo({
              url: "/pages/pay/paidOrder/paidOrder?order_no=" + e.order_no
          });
      } else wx.navigateTo({
          url: "/pages/userOrder/orderDetail/orderDetail?order_no=" + e.order_no
      });
  },
  callServerHandler: function(t) {
      var a = this, n = (wx.getStorageSync("access_token"), wx.getStorageSync("user_info")), i = this.data.endAddress, s = this.data.isReadProtocol, r = wx.getStorageSync("OPEN_LIMIT_DES");
      if (!i) {
          if (r) return void e.showToast("请输入目的地", "none");
        //   this.data.endAddress = this.data.startAddress;
      }
      if (n) if (s) {
          if (!n.phone) return this.setData({
              show_bind_phone: !0
          }), void setTimeout(function() {
              a.setData({
                  show_bind_phone: !1
              }), wx.navigateTo({
                  url: "/pages/logs/logs"
              });
          }, 1500);
          !this.excId || this.hideQrcode ? this.create_order(t) : this.create_QR_order(this.excId);
      } else wx.showModal({
          title: "提示",
          content: "请确认服务协议"
      }); else o.showToast("请先登录", 0, 1e3, function() {
          o.navTo("/pages/logs/logs");
      });
  },
  orderGoingHandler: function() {
      e.showToast("您还没有进行中的订单", "none");
  },
  mark_icon: function() {
      var e = this, t = this.data.startAddress, a = this.data.endAddress, o = [];
      if (t) {
          o[0] = {
              id: 0,
              iconPath: "../../../images/user/icon-44.png",
              latitude: t.location.lat,
              longitude: t.location.lng,
              width: 40,
              height: 40
          };
          var n = {
              location: {
                  lat: t.location.lat,
                  lng: t.location.lng
              }
          };
      }
      a && (o[1] = {
          id: 1,
          iconPath: "/images/user/icon-43.png",
          latitude: a.location.lat,
          longitude: a.location.lng,
          width: 40,
          height: 40
      }), t && a && this.setData({
          userAddress: n,
          scale: 13
      }), e.setData({
          make: o
      });
  },
  onShow: function() {
      

        if (typeof this.getTabBar === 'function' &&
          this.getTabBar()) {
          this.getTabBar().setData({
            selected: 1
          })
        }
      
  






      var e = this;
      wx.getStorage({
        key: 'travel_type',
        success(res) {
          e.setData({travel_type:res.data})
        }
      })
      
      o.cache("couponMask") || this.checkCoupon(), wx.getStorageSync("get_order") && this.setData({
          get_order: wx.getStorageSync("get_order")
      }), this.get_line_and_count_distance(), e.order_check(), 1 != this.data.flag && e.get_driver_lat_lng(), 
      this.timer = setInterval(e.get_driver_lat_lng, 1e4), this.data.flag = this.data.flag + 1;
  },
  getSettings: function() {
      wx.getSetting({
          success: function(e) {
              void 0 != e.authSetting["scope.userLocation"] && 1 != e.authSetting["scope.userLocation"] ? wx.showModal({
                  title: "请求授权当前位置",
                  content: "需要获取您的地理位置，请确认授权",
                  success: function(e) {
                      e.cancel ? wx.showToast({
                          title: "拒绝授权",
                          icon: "none",
                          duration: 1e3
                      }) : e.confirm && wx.openSetting({
                          success: function(e) {
                              1 == e.authSetting["scope.userLocation"] ? (wx.showToast({
                                  title: "授权成功",
                                  icon: "success",
                                  duration: 1e3
                              }), wx.getLocation({
                                  success: function(e) {}
                              })) : wx.showToast({
                                  title: "授权失败",
                                  icon: "none",
                                  duration: 1e3
                              });
                          }
                      });
                  }
              }) : (e.authSetting["scope.userLocation"], wx.getLocation({
                  success: function(e) {}
              }));
          }
      });
  },
  get_driver_lat_lng: function() {
      var e = this, a = this.data.startAddress, n = this.data.endAddress;
      if (1 != this.data.showDriver) return !1;
      o.request({
          url: t.user.getDriverPosition,
          data: {
              lat: e.data.driverPosition.lat,
              lng: e.data.driverPosition.lng
          },
          success: function(t) {
              for (var o = [], i = t.data, s = 0; s < i.length; s++) i[s].real_name = i[s].real_name.substring(0, 1) + "师傅", 
              null != i[s].location && o.push({
                  iconPath: "../../../images/user/icon-50.png",
                  id: s,
                  latitude: i[s].location.lat,
                  longitude: i[s].location.lng,
                  width: 60,
                  height: 60,
                  callout: {
                      content: i[s].real_name + "   " + i[s].distance + "km",
                      bgColor: "#fff",
                      color: "#000",
                      padding: "6",
                      display: "ALWAYS",
                      borderRadius: "20",
                      borderColor: "#B1F9FE",
                      borderWidth: "1"
                  }
              });
              a && o.push({
                  id: o.length,
                  iconPath: "../../../images/user/icon-44.png",
                  latitude: a.location.lat,
                  longitude: a.location.lng,
                  width: 40,
                  height: 40
              }), n && o.push({
                  id: o.length + 1,
                  iconPath: "/images/user/icon-43.png",
                  latitude: n.location.lat,
                  longitude: n.location.lng,
                  width: 40,
                  height: 40
              }), e.setData({
                  make: o
              });
          }
      });
  },
  get_line_and_count_distance: function(e) {
      var a = this, n = this.data.startAddress, i = this.data.endAddress;
      if (n && i) {
          if (this.getPolyline(n, i), !n && !i) return;
        
          o.request({
              url: t.order_forecast.order_forecast,
              method: "post",
              data: {
                  start: JSON.stringify(n),
                  end: JSON.stringify(i),
                  dat: a.data.date.join(","),
                  hours: a.data.hours.join(","),
                  minute: a.data.minute.join(","),
                  about_time: a.data.about_time.join(","),
                  travel_type : o.travel_type
              },
              success: function(e) {
                  a.setData({
                      price: e.data.price,
                      distance: e.data.actual_km,
                      is_distance: !0, 
                      travel_type:o.travel_type,
                      estimated_form_time:e.data.estimated_form_time
                  });
              }
          });
      }
  },
  getPolyline: function(e, t) {
      var a = this, o = this.data.polyline, i = e.location.lat + "," + e.location.lng + "&to=" + t.location.lat + "," + t.location.lng ,p = '&policy=LEAST_DISTANCE';
      wx.request({
          url: "https://apis.map.qq.com/ws/direction/v1/driving/?from=" + i + "&key=" + n + p,
          header: {
              "content-type": "application/json"
          },
          success: function(e) {
              if (384 != e.data.status) {
                  for (var t = e.data.result.routes[0].polyline, n = 2; n < t.length; n++) t[n] = t[n - 2] + t[n] / 1e6;
                  for (var i = [], s = 0; s < t.length; s += 2) i[i.length] = {
                      longitude: t[s + 1],
                      latitude: t[s]
                  };
                  o[0].points = i, a.setData({
                      polyline: o
                  });
              }
          },
          fail: function() {}
      });
  },
  get_distance: function(e, t, a) {
      i.calculateDistance({
          from: {
              latitude: e.location.lat,
              longitude: e.location.lng
          },
          to: [ {
              latitude: t.location.lat,
              longitude: t.location.lng
          } ],
          success: function(e) {
              a({
                  distance: e.result
              });
          },
          fail: function(e) {
              a(e);
          },
          complete: function(e) {}
      });
  },
  loginHandler: function(a) {
      var n = this;
      "登录" === this.data.buttonText ? e.loginHandler(function(e) {
          n.getUserInfo();
      }) : (o.request({
          url: t.user.loginout,
          method: "post",
          data: {},
          success: function(e) {
              1 == e.code && (wx.removeStorageSync("userMessage"), wx.removeStorageSync("phonep"), 
              wx.removeStorageSync("access_token"), wx.removeStorage({
                  key: "access_token"
              }), wx.removeStorageSync("uid")), wx.showToast({
                  title: e.msg,
                  duration: 2e3
              });
          }
      }), this.setData({
          avatar: "../../../images/user/icon-07.png",
          username: "未登录",
          buttonText: "登录",
          phone: ""
      }));
  },
  getAuthorizationImg: function() {
      var e = this;
      wx.showLoading(), o.request({
          url: t.share.authorization,
          method: "post",
          data: {},
          success: function(t) {
              if (wx.hideLoading(), 1 != t.code) return wx.showToast({
                  title: t.msg,
                  icon: "none"
              }), !1;
              e.setData({
                  authorize: t.data.image
              });
          }
      });
  },
  getUserInfo: function(e) {
      var a = this;
      this.getSettings(), wx.showLoading({}), wx.login({
          success: function(e) {
              e.code && wx.getUserProfile({
                  success: function(n) {
                      console.log(n);
                      wx.hideLoading(), o.request({
                          url: t.user.login,
                          method: "post",
                          data: {
                              code: e.code,
                              iv: n.iv,
                              encryptedData: n.encryptedData,
                              id: a.data.fenxiaoId
                          },
                          success: function(e) {
                              if (1 == e.code) {
                                  e.data.is_binding;
                                  wx.showToast({
                                      title: "登录成功",
                                      icon: "success",
                                      duration: 2e3
                                  }), wx.setStorageSync("user_info", e.data), wx.setStorageSync("uid", e.data.id), 
                                  a.setData({
                                      authStatus: !0,
                                      is_GZH: !0
                                  }), wx.setStorageSync("access_token", e.data.access_token), a.order_check();
                              } else wx.removeStorage({
                                  key: "access_token"
                              }), wx.removeStorage({
                                  key: "uid"
                              }), wx.showToast({
                                  title: "登录失败",
                                  icon: "none",
                                  duration: 2e3
                              });
                          }
                      });
                  }
              });
          }
      });
  },
  intoPageHandler: function(t) {
    var a = this, n = (wx.getStorageSync("access_token"), wx.getStorageSync("user_info")),  s = this.data.isReadProtocol
    if (n) if (s) {
       if (!n.phone) return this.setData({
           show_bind_phone: !0
       }), void setTimeout(function() {
           a.setData({
               show_bind_phone: !1
           }), wx.navigateTo({
               url: "/pages/logs/logs"
           });
       }, 1500);
       !this.excId || this.hideQrcode ? this.create_order(t) : this.create_QR_order(this.excId);
   } else wx.showModal({
       title: "提示",
       content: "请确认服务协议"
   }); else o.showToast("请先登录", 0, 1e3, function() {
       o.navTo("/pages/logs/logs");
   });
      e.intoPageHandler(t.currentTarget.dataset.skip);
  },
  startAddressBtn: function() {
      var e = this;
      wx.chooseLocation({
          success: function(t) {
              e.setData({
                  startAddress: {
                      title: t.name,
                      address: t.address,
                      location: {
                          lat: t.latitude,
                          lng: t.longitude
                      }
                  }
              }), e.mark_icon(), e.get_line_and_count_distance();
          }
      });
  },
  endAddress: function() {
      var e = this;
      wx.chooseLocation({
          success: function(t) {
              e.setData({
                  endAddress: {
                      title: t.name,
                      address: t.address,
                      location: {
                          lat: t.latitude,
                          lng: t.longitude
                      }
                  }
              }), e.get_line_and_count_distance(), e.mark_icon();
          }
      });
  },
  relstiveServerHandler: function() {
      e.callPhoneHandler(wx.getStorageSync("servernum"));
  },
  selectTimeShowTimeHandler: function() {
      this.setData({
          showTimeContainer: !0,
          homeHandlerShow: !1
      }), this.selectTimeHandler(0, 0, 0);
  },
  getTimeHandlerCancle: function() {
      this.setData({
          showTimeContainer: !1,
          homeHandlerShow: !0
      });
  },
  getTimeHandlerOk: function() {
      var e = this.data, t = e.hours, a = e.minute;
      this.data.endAddress ? this.get_line_and_count_distance() : wx.showToast({
          title: "请选择目的地",
          icon: "none"
      }), this.setData({
          now_hours: t,
          now_minute: a,
          showTimeContainer: !1,
          homeHandlerShow: !0
      });
  },
  bindTimeChange: function(e) {
      this.setData({
          about_time: e.detail.value
      }), this.selectTimeHandler(e.detail.value[0], e.detail.value[1], e.detail.value);
  },
  selectTimeHandler: function(e, t, a) {
      var o = this.data, n = o.hours, i = o.minute, s = new Date(), r = s.getHours(), d = s.getMinutes() + 15;
      if (d < 60 && n.push(r + "点"), d >= 60 && (d -= 60, r += 1), i = [], n = [], 0 === e && 0 === t) {
          for (c = r; c < 24; c++) n.push(c + "点");
          for (c = d; c < 60; c += 10) i.push(c);
          this.setData({
              hours: n,
              minute: i
          });
      } else if (0 === e && 0 !== t) {
          n.push(r + "点");
          for (c = r + 1; c < 24; c++) n.push(c + "点");
          for (c = 0; c < 60; c += 10) i.push(c);
          this.setData({
              hours: n,
              minute: i
          });
      } else if (0 !== e) {
          for (c = 0; c < 24; c++) n.push(c + "点");
          for (var c = 0; c < 60; c += 10) i.push(c);
          this.setData({
              hours: n,
              minute: i
          });
      }
  },
  changeIcon: function() {
      var e = this, t = this.data.controls;
      wx.getSystemInfo({
          success: function(a) {
              var o = a.windowWidth / 750 * 500, n = a.windowHeight - o;
              t[1] = {
                  id: 2,
                  iconPath: "../../../images/user/icon-30.png",
                  position: {
                      top: n - 56,
                      left: 10,
                      width: 50,
                      height: 50
                  },
                  clickable: !0
              }, e.setData({
                  winPath: {
                      w: a.windowWidth,
                      h: a.windowHeight
                  },
                  map_height: n / 2 * 2,
                  controls: t
              });
          }
      });
  },
  onUnload: function() {
      this.setData({
          end: ""
      }), o.wsRemoveOnline(this.onlineCallbackVar);
  },
  onHide: function() {
      clearInterval(this.timer), this.setData({
          end: ""
      });
  },
  formSubmit: function(e) {
      // console.log(e);
      this.callServerHandler(null);
  },
  onShareAppMessage: function() {
      return {
          title: o.shareAppMessage().title,
          imageUrl: o.shareAppMessage().imageUrl,
          desc: o.shareAppMessage().desc,
          path: o.shareAppMessage().path
      };
  },
  onShareTimeline: function() {
      return {
          title: o.shareAppMessage().title,
          imageUrl: o.shareAppMessage().imageUrl
      };
  },
  taxi(){
      console.log('出租车页面');
      o.travel_type = 2
      console.log(o.travel_type);
      this.setData({
          newtop:false ,
          'endAddress.title':'',
      })
  },
  drivingagent(){
      console.log('代驾状态');
      o.travel_type = 1 
      console.log(o.travel_type);
      this.setData({
          newtop: true,
          'endAddress.title':'',
      })
  },
  // 下拉
  opens:function (e) {
      switch (e.currentTarget.dataset.item) {
       case "1":
        if (this.data.isstart) {
         this.setData({
          isstart: false,
         });
        }
        else {
         this.setData({
          isstart: true,
         });
        }
        break;
      }
     },
     onclicks1: function (e) {
      var index = e.currentTarget.dataset.index;
      let name = this.data.slist[index].name;
      this.setData({
       isstart: false,
       isfinish: false,
       isdates: false,
       start: this.data.slist[index].name,
       finish: "目的地"
      })
     }
});